import logging

from django.conf import settings
from django.core.mail import send_mail
from django.template import loader

logger =  logging.getLogger('django')

def send_ad_email(email):
    # 3.1 得到要发送邮件的网页模板内容
    template = loader.get_template('email_ad.html')
    context = {
        'email': email,
        'price': 9.9
    }
    html_message = template.render(context)

    # 3.2 发送邮件
    try:
        send_mail(
            '美多商城搞活动啦！', '',
            settings.DEFAULT_FROM_EMAIL, [email],
            html_message=html_message
        )
    except Exception as err:
        logger.error('给{}发送广告邮件失败，错误是:{}'.format(email, str(err)) )
